package org.example.controller;

import org.example.bean.Cake;
import org.example.bean.CakeCatalog;
import org.example.service.CakeCatelogService;
import org.example.service.CakeService;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CakeController {

    private CakeService cakeService;

    @Autowired
    public void setCakeService(CakeService cakeService) {
        this.cakeService = cakeService;
    }

    @ResponseBody
    @RequestMapping("/finAll")
    public Result cakeListServlet() {
        List<Cake> cakes = cakeService.finAll();
        System.out.println("获得所有商品信息");
        Result result = new Result();
        result.result = cakes;
        return result;
    }
    @ResponseBody
    @PostMapping("/delcakeid")
    public Result delcakeservlet(String id){
        cakeService.delcakeid(Integer.parseInt(id));
        System.out.println("删除商品操作执行成功");
        Result res = new Result();
        res.flag = 1;
        return res;
    }
}
